package Test;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @leiwenkang 2018-01-22 16:09.
 */
public class ThreadPoolExecutorTest {
    private static ExecutorService cacheThreadPool = new ThreadPoolExecutor(
            4,
            6,
            0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(1000, true),
            new ThreadPoolExecutor.AbortPolicy());
    public static void main(String[] args) {

        for(int i =1;i<=100;i++){
            final int index=i ;
            try{
                Thread.sleep(1000);
            }catch(InterruptedException  e ) {
                e.printStackTrace();
            }
            cacheThreadPool.execute(new Runnable(){
                @Override
                public void run() {
                    System.out.println("第" +index +"个线程" +Thread.currentThread().getName());
                }
            });
        }
    }
}
